<?php


namespace App\Http\Controllers\Platform;


use App\Http\Controllers\Controller;
use App\Utils\ResultUtil;
use Illuminate\Http\Request;

class CaptchaController extends Controller
{

    public function verify(Request $request){
        $data = $request->post('datas');
        if (empty($data)){
            return false;
        }
        $data =json_decode($data,true);
        $size = count($data);
        $sum = array_sum($data) ;
        $avg = bcdiv($sum,$size,1);

        $sum2 = 0.0;
        foreach ($data as $d){
            $sum2 = bcadd($sum2,pow($d-$avg,2),1);
        }
        $stddev = bcdiv($sum2,$size,1);
        $r = $stddev != 0;
        return ResultUtil::data(['r'=>$stddev]);

    }

}
